import java.util.Arrays;


public class Math_N {
	public static double distance(int xpos1, int ypos1, int xpos2, int ypos2){
    	float dx = xpos1-xpos2;
    	float dy = ypos1-ypos2;
    	
    	return Math.sqrt((dx*dx)+(dy*dy));
    }
	
	public static double angle(int xpos1, int ypos1, int xpos2, int ypos2){
		float dx = xpos2-xpos1;
    	float dy = ypos2-ypos1;
    	double angle = Math.atan(dy/dx) * (180.0/Math.PI);  
    	  
        if(dx < 0.0) {  
            angle += 180.0;  
        } else {  
            if(dy<0.0) angle += 360.0;  
        }  
      
        return angle;  
	}
	
	public static int getLenB(String text){
		int length = 0;
		char[] tmpChar = new char[text.length()];
		
		for(int i=0;i<tmpChar.length;i++){
			tmpChar[i] = text.charAt(i);
			
			if(tmpChar[i]<128){
				length++;
			}else{
				length+=2;
			}
		}
		return length;
	}
	
	public static String getCenterString(String text, int size){
		
		String result=null;
		char[] chr_spaces = null;
		int length = Math_N.getLenB(text);
		
		if(length==size){
			result=text;
		}else{
			if(length%2==0){
				chr_spaces=new char[(int)((size-length)/2)];
	    		Arrays.fill(chr_spaces, ' ');
	    		result=new String(chr_spaces)+text+new String(chr_spaces);
			}else{
				chr_spaces=new char[(int)((size-length)/2)];
				Arrays.fill(chr_spaces, ' ');
	    		result=new String(chr_spaces)+" "+text+new String(chr_spaces);
			}
		}
		
		return result;
	}
	
	public static String getRightString(String text, int size){
		
		String result=null;
		char[] chr_spaces = null;
		int length = Math_N.getLenB(text);
		
		chr_spaces=new char[size-length];
		Arrays.fill(chr_spaces, ' ');
		result=new String(chr_spaces)+text;
		
		return result;
	}
}
